//
//  ViewController.m
//  TermOfSectionB
//
//  Created by 韩震明 on 15/11/27.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UITabBarController *tab;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tab = [[UITabBarController alloc] init];
    
    [self setUpAllChildViewController];
}

/**
 *  添加所有子控制器方法
 */
- (void)setUpAllChildViewController{
    // 1.添加第一个控制器
    SYSpecialViewController *specialVC = [[SYSpecialViewController alloc]init];
    [self setUpOneChildViewController:specialVC image:[UIImage imageNamed:@"zhuanti"] title:@"专题"];
    
    // 2.添加第2个控制器
    SYDesignerViewController *designerVC = [[SYDesignerViewController alloc]init];
    [self setUpOneChildViewController:designerVC image:[UIImage imageNamed:@"disgner.png"] title:@"设计师"];
    
    // 3.添加第3个控制器
    SYShoppingViewController *shoppingVC = [[SYShoppingViewController alloc]init];
    [self setUpOneChildViewController:shoppingVC image:[UIImage imageNamed:@"str.png"] title:@"随便逛"];
    
    // 4.添加第4个控制器
    SYLoginViewController *loginVC = [[SYLoginViewController alloc]init];
    [self setUpOneChildViewController:loginVC image:[UIImage imageNamed:@"user.png"] title:@"我的"];
}


/**
 *  添加一个子控制器的方法
 */
- (void)setUpOneChildViewController:(UIViewController *)viewController image:(UIImage *)image title:(NSString *)title{
    
    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:viewController];
    navC.title = title;
    navC.tabBarItem.image = image;
    [navC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarImage"] forBarMetrics:UIBarMetricsDefault];
    if ([title isEqualToString:@"随便逛"]) {
        title = nil;
    }
    viewController.navigationItem.title = title;
    
    [self addChildViewController:navC];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
